<template>
  <div>
    <van-popup position="right" v-model="editShow">
      <van-nav-bar
        title="编辑简介"
        right-text="提交"
        left-arrow
        @click-left="onClickLeft"
        @click-right="onClickRight"
      />
      <van-form ref="form">
        <van-field
          :rules="rules"
          v-model="inputValue"
          placeholder="请输入用户名"
        />
      </van-form>
    </van-popup>
  </div>
</template>

<script>
export default {
  data () {
    return {
      editShow: false,
      inputValue: '',
      rules: [
        { required: true, message: '必填', tirgger: 'onChange' },
        {
          validator: value => {
            return value !== this.$store.state.login.userInfo.name
          },
          message: '不能和当前值一样',
          tirgger: 'onChange'
        }
      ]
    }
  },
  methods: {
    onClickLeft () {
      this.editShow = false
    },
    onClickRight () {
      this.$refs.form
        .validate()
        .then(() => {
          this.$parent.editUserInfo({
            key: 'name',
            value: this.inputValue
          })
          this.editShow = false
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="less" scoped>
.van-popup {
  width: 100%;
  height: 100%;
}
::v-deep .van-field__control {
  background-color: #ccc;
}
</style>
